import { getStream } from '../Core/connect'
import * as MathUtils from '../Math/MathUtils'

export const aspects = {
    // 开始两点构面
    TwoAspects(makeArea:boolean) {
        const sessionId = MathUtils.generateUUID()
        return new Promise(function (resolve) {
            const stream = getStream()
            const str = {EventFunction: 'TwoAspects',sessionId:sessionId,makeArea:makeArea}
            stream.emitUIInteraction(str)
            const getTwoAspects = (data: any) => {
                const returnData = JSON.parse(data)
                if(returnData.sessionId === sessionId){
                    console.log('矩形点位',returnData)
                    resolve(returnData)
                }
            }
            stream.addResponseEventListener(`getTwoAspects`, getTwoAspects)
        })
    },
    
    // 多点绘制面
    multipoint(makeArea:boolean,fun:Function) {
        const sessionId = MathUtils.generateUUID()
        const stream = getStream()
        const str = {EventFunction: 'multipoint',sessionId:sessionId,makeArea:makeArea}
        stream.emitUIInteraction(str)
        const getMultipoint = (data: any) => {
            const returnData = JSON.parse(data)
            if(returnData.sessionId === sessionId){
                console.log('面列表',returnData)
                fun(returnData)
            }
        }
        stream.addResponseEventListener(`getMultipoint`, getMultipoint)
    },
    // 停止编辑
    stopTwoAspects() {
        const stream = getStream()
        const str = {EventFunction: 'stopAspects'}
        stream.removeResponseEventListener(`getTwoAspects`)
        stream.removeResponseEventListener(`getMultipoint`)
        stream.emitUIInteraction(str)
    },
    // 移除所有面
    removeAspects() {
        const stream = getStream()
        const str = {EventFunction: 'removeAspects'}
        stream.emitUIInteraction(str)
    },
    stopalldraw(){
        const stream = getStream()
        const str = {EventFunction: 'stopalldraw'}
        stream.emitUIInteraction(str)
    }
}